package cn.jy.nvr.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.jy.nvr.datasource.DataSourceConst;
import cn.jy.nvr.datasource.DataSourceContextHolder;
import cn.jy.nvr.domain.NewProvider;
import cn.jy.nvr.domain.ProviderAssay;
import cn.jy.nvr.domain.ProviderBaseInfo;
import cn.jy.nvr.domain.ProviderBodyCheck;
import cn.jy.nvr.domain.ProviderChestCheck;
import cn.jy.nvr.domain.ProviderCollection;
import cn.jy.nvr.domain.ProviderCost;
import cn.jy.nvr.domain.ProviderHeat;
import cn.jy.nvr.domain.ProviderProcess;
import cn.jy.nvr.domain.ProviderRegister;
import cn.jy.nvr.domain.ProviderSampleAssay;
import cn.jy.nvr.mapper.NewProviderMapper;
import cn.jy.nvr.mapper.ProviderAssayMapper;
import cn.jy.nvr.mapper.ProviderBaseInfoMapper;
import cn.jy.nvr.mapper.ProviderBodyCheckMapper;
import cn.jy.nvr.mapper.ProviderChestCheckMapper;
import cn.jy.nvr.mapper.ProviderCollectionMapper;
import cn.jy.nvr.mapper.ProviderCostMapper;
import cn.jy.nvr.mapper.ProviderHeatMapper;
import cn.jy.nvr.mapper.ProviderProcessMapper;
import cn.jy.nvr.mapper.ProviderRegisterMapper;
import cn.jy.nvr.mapper.ProviderSampleAssayMapper;
import cn.jy.nvr.utils.TimeUtils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

   

@Controller
public class ProviderProcessController
{
	
	@Autowired
	ProviderProcessMapper processMapper;
	 
	@RequestMapping("display/ProviderProcess")
	public String Collecting(HttpServletRequest request,HttpServletResponse response){
		 response.setContentType("text/html");
		 response.setCharacterEncoding("utf-8");
		 String callback = request.getParameter("callback"); 
		 
		 String nowDate = request.getParameter("date");
		 List<ProviderProcess> providerProcessByDate=null;
		 if(!nowDate.isEmpty()){
			  DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			  providerProcessByDate = processMapper.getProviderProcessByDate(nowDate);
		 }
		 
		ObjectMapper mapper = new ObjectMapper();
		String json = null;
		try {
			json = mapper.writeValueAsString(providerProcessByDate);
		} catch (JsonProcessingException e1) {
			e1.printStackTrace();
		}

		String retStr = callback + "(" + json + ")";
		try {
			PrintWriter out = response.getWriter();
			out.print(retStr);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

}